package com.resource.common.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
//对公共字段进行处理
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    //插入操作自动填充
    public void insertFill(MetaObject metaObject) {
            log.info(metaObject.toString());

            metaObject.setValue("gmt_create", LocalDateTime.now());
            metaObject.setValue("gmt_modified",LocalDateTime.now());
            //这个可以用threadlocal线程进行处理,因为这个数据是可变的，要根据不同的用户来获取

    }

    @Override
    //修改操作自动填充
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("gmt_modified",LocalDateTime.now());
    }
}
